#include <bits/stdc++.h>

using namespace std;

class DisjointSetUnion
{
private:
    unordered_map<int, int> f, rank;
    int number_of_connectedComponent;

public:
    DisjointSetUnion() { number_of_connectedComponent = 0; }
    int find(int x)
    {
        if (!f.count(x))
        {
            f[x] = x;
            rank[x] = 1;
            ++number_of_connectedComponent;
        }
        return f[x] == x ? x : f[x] = find(f[x]);
    }

    // true->x,y is connected, false->not connected
    bool unionSet(int x, int y)
    {
        int fx = find(x), fy = find(y);
        if (fx == fy)
        {
            return true;
        }
        --number_of_connectedComponent;
        if (rank[fx] < rank[fy])
        {
            swap(fx, fy);
        }
        rank[fx] += rank[fy];
        f[fy] = fx;
        return false;
    }

    int numberOfConnectedComponent()
    {
        return number_of_connectedComponent;
    }
};

int main()
{
    size_t T;
    cin >> T;
    int ans1 = -1, ans2 = -1;
    bool found = false;
    DisjointSetUnion djs;
    for (size_t edgeNum = 1; edgeNum <= T; ++edgeNum)
    {
        int u, v;
        cin >> u >> v;

        if (!found && djs.unionSet(u, v))
        {
            ans1 = min(u, v);
            ans2 = max(u, v);
            found = true;
        }
    }
    cout << ans1 << " " << ans2 << endl;
    // system("pause");
    return 0;
}